#!/usr/bin/python3


def get_0_count(n):
    if n == 0:
        return 1
    elif n == 1:
        return 0
    elif n % 2 == 1:
        return 2 * get_0_count((n-1) / 2)
    elif n % 2 == 0:
        return 2 * get_0_count(n / 2) + 1
    else:
        return 0


try:
    n = int(input())
    print(get_0_count(n))
except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
